<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

$orgMap = [];


class FeelingTone extends Model
{
    protected  $table='feeling_tone';

    protected $fillable = [
        'comment_count'
    ];

    protected $appends = array('preview_url');

    protected $casts = [
        'photo' => 'array',
    ];

    public function getPreviewUrlAttribute() {
        if (!$this->org_id) {
            return null;
        }

        $org = null;

        if (isset($orgMap[$this->org_id])) {
            $org = $orgMap[$this->org_id];
        } else {
            $orgMap[$this->org_id] = $org = Org::findOrFail($this->org_id);
        }

        return $org->wechat_app_url.'/my/circledetail/'. $this->id;
    }


    public function author() {
        return $this->belongsTo('App\User', 'user_id', 'id');
    }

    public function project() {
        return $this->belongsTo('App\Models\Project', 'relation_id', 'id');
    }

    public function team() {
        return $this->belongsTo('App\Models\Team', 'relation_id', 'id');
    }
}
